package com.heima.admin.job;

import cn.hutool.core.collection.CollectionUtil;
import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.feigns.wemedia.WemediaFeign;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author TheCai
 * @date 2021/6/2 21:20
 **/

@Component
@Slf4j
public class WeMediaNewsAutoScanJob {
    @Autowired
    WemediaNewsAutoScanService wemediaNewsAutoScanService;
    @Autowired
    WemediaFeign wemediaFeign;

    /**
     * 定时发布文章的任务
     * @param param
     * @return
     */
    @XxlJob("wemediaAutoScanJob")
    public ReturnT wemediaAutoScanJob(String param){
        log.info("==============定时发布文章任务被触发了==================");
    // 1.远程调用自媒体查询待发布文章
        List<Integer> releaseList = wemediaFeign.findRelease();
    // 2.调用自动发布访问  发布文章
    if (CollectionUtil.isNotEmpty(releaseList)) {
        //遍历调用自动发布
      releaseList.forEach(wemediaNewsAutoScanService::autoScanByMediaNewsId);
}

        return ReturnT.SUCCESS;//任务成功
    }

}
